home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_libxml.idb / usr / freeware / include / gnome-xml / tree.h.z / tree.h
Encoding:
C/C++ Source or Header  |  1999-07-16  |  12.1 KB  |  388 lines

  1. /*
  2.  * tree.h : describes the structures found in an tree resulting
  3.  *          from an XML parsing.
  4.  *
  5.  * See Copyright for the status of this software.
  6.  *
  7.  * Daniel.Veillard@w3.org
  8.  */
  9.  
  10. #ifndef __XML_TREE_H__
  11. #define __XML_TREE_H__
  12.  
  13.  
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17.  
  18. #include <stdio.h>
  19.  
  20. /*
  21.  * The different element types carried by an XML tree
  22.  *
  23.  * NOTE: This is synchronized with DOM Level1 values
  24.  *       See http://www.w3.org/TR/REC-DOM-Level-1/
  25.  */
  26. typedef enum {
  27.     XML_ELEMENT_NODE=        1,
  28.     XML_ATTRIBUTE_NODE=        2,
  29.     XML_TEXT_NODE=        3,
  30.     XML_CDATA_SECTION_NODE=    4,
  31.     XML_ENTITY_REF_NODE=    5,
  32.     XML_ENTITY_NODE=        6,
  33.     XML_PI_NODE=        7,
  34.     XML_COMMENT_NODE=        8,
  35.     XML_DOCUMENT_NODE=        9,
  36.     XML_DOCUMENT_TYPE_NODE=    10,
  37.     XML_DOCUMENT_FRAG_NODE=    11,
  38.     XML_NOTATION_NODE=        12
  39. } xmlElementType;
  40.  
  41. /*
  42.  * Size of an internal character representation.
  43.  *
  44.  * Currently we use 8bit chars internal representation for memory efficiency,
  45.  * but the parser is not tied to that, just define UNICODE to switch to
  46.  * a 16 bits internal representation. Note that with 8 bits wide
  47.  * CHARs one can still use UTF-8 to handle correctly non ISO-Latin
  48.  * input.
  49.  */
  50. #ifdef UNICODE
  51. typedef unsigned short CHAR;
  52. #else
  53. typedef unsigned char CHAR;
  54. #endif
  55.  
  56. /*
  57.  * a DTD Notation definition
  58.  */
  59.  
  60. typedef struct xmlNotation {
  61.     const CHAR               *name;    /* Notation name */
  62.     const CHAR               *PublicID;    /* Public identifier, if any */
  63.     const CHAR               *SystemID;    /* System identifier, if any */
  64. } xmlNotation;
  65. typedef xmlNotation *xmlNotationPtr;
  66.  
  67. /*
  68.  * a DTD Attribute definition
  69.  */
  70.  
  71. typedef enum {
  72.     XML_ATTRIBUTE_CDATA = 1,
  73.     XML_ATTRIBUTE_ID,
  74.     XML_ATTRIBUTE_IDREF    ,
  75.     XML_ATTRIBUTE_IDREFS,
  76.     XML_ATTRIBUTE_ENTITY,
  77.     XML_ATTRIBUTE_ENTITIES,
  78.     XML_ATTRIBUTE_NMTOKEN,
  79.     XML_ATTRIBUTE_NMTOKENS,
  80.     XML_ATTRIBUTE_ENUMERATION,
  81.     XML_ATTRIBUTE_NOTATION
  82. } xmlAttributeType;
  83.  
  84. typedef enum {
  85.     XML_ATTRIBUTE_NONE = 1,
  86.     XML_ATTRIBUTE_REQUIRED,
  87.     XML_ATTRIBUTE_IMPLIED,
  88.     XML_ATTRIBUTE_FIXED
  89. } xmlAttributeDefault;
  90.  
  91. typedef struct xmlEnumeration {
  92.     struct xmlEnumeration    *next;    /* next one */
  93.     const CHAR               *name;    /* Enumeration name */
  94. } xmlEnumeration;
  95. typedef xmlEnumeration *xmlEnumerationPtr;
  96.  
  97. typedef struct xmlAttribute {
  98.     const CHAR            *elem;    /* Element holding the attribute */
  99.     const CHAR            *name;    /* Attribute name */
  100.     xmlAttributeType       type;    /* The type */
  101.     xmlAttributeDefault    def;        /* the default */
  102.     const CHAR            *defaultValue;/* or the default value */
  103.     xmlEnumerationPtr      tree;        /* or the enumeration tree if any */
  104. } xmlAttribute;
  105. typedef xmlAttribute *xmlAttributePtr;
  106.  
  107. /*
  108.  * a DTD Element definition.
  109.  */
  110. typedef enum {
  111.     XML_ELEMENT_CONTENT_PCDATA = 1,
  112.     XML_ELEMENT_CONTENT_ELEMENT,
  113.     XML_ELEMENT_CONTENT_SEQ,
  114.     XML_ELEMENT_CONTENT_OR
  115. } xmlElementContentType;
  116.  
  117. typedef enum {
  118.     XML_ELEMENT_CONTENT_ONCE = 1,
  119.     XML_ELEMENT_CONTENT_OPT,
  120.     XML_ELEMENT_CONTENT_MULT,
  121.     XML_ELEMENT_CONTENT_PLUS
  122. } xmlElementContentOccur;
  123.  
  124. typedef struct xmlElementContent {
  125.     xmlElementContentType     type;    /* PCDATA, ELEMENT, SEQ or OR */
  126.     xmlElementContentOccur    ocur;    /* ONCE, OPT, MULT or PLUS */
  127.     const CHAR               *name;    /* Element name */
  128.     struct xmlElementContent *c1;    /* first child */
  129.     struct xmlElementContent *c2;    /* second child */
  130. } xmlElementContent;
  131. typedef xmlElementContent *xmlElementContentPtr;
  132.  
  133. typedef enum {
  134.     XML_ELEMENT_TYPE_EMPTY = 1,
  135.     XML_ELEMENT_TYPE_ANY,
  136.     XML_ELEMENT_TYPE_MIXED,
  137.     XML_ELEMENT_TYPE_ELEMENT
  138. } xmlElementTypeVal;
  139.  
  140. typedef struct xmlElement {
  141.     const CHAR          *name;        /* Element name */
  142.     xmlElementTypeVal    type;        /* The type */
  143.     xmlElementContentPtr content;    /* the allowed element content */
  144. } xmlElement;
  145. typedef xmlElement *xmlElementPtr;
  146.  
  147. /*
  148.  * An XML namespace.
  149.  * Note that prefix == NULL is valid, it defines the default namespace
  150.  * within the subtree (until overriden).
  151.  */
  152.  
  153. typedef enum {
  154.     XML_GLOBAL_NAMESPACE = 1,    /* old style global namespace */
  155.     XML_LOCAL_NAMESPACE        /* new style local scoping */
  156. } xmlNsType;
  157.  
  158. typedef struct xmlNs {
  159.     struct xmlNs  *next;    /* next Ns link for this node  */
  160.     xmlNsType      type;    /* global or local */
  161.     const CHAR    *href;    /* URL for the namespace */
  162.     const CHAR    *prefix;    /* prefix for the namespace */
  163. } xmlNs;
  164. typedef xmlNs *xmlNsPtr;
  165.  
  166. /*
  167.  * An XML DtD, as defined by <!DOCTYPE.
  168.  */
  169. typedef struct xmlDtd {
  170.     const CHAR    *name;    /* Name of the DTD */
  171.     const CHAR    *ExternalID;    /* External identifier for PUBLIC DTD */
  172.     const CHAR    *SystemID;    /* URI for a SYSTEM or PUBLIC DTD */
  173.     void          *notations;   /* Hash table for notations if any */
  174.     void          *elements;    /* Hash table for elements if any */
  175.     void          *attributes;  /* Hash table for attributes if any */
  176.     void          *entities;    /* Hash table for entities if any */
  177.     /* struct xmlDtd *next;     * next  link for this document  */
  178. } xmlDtd;
  179. typedef xmlDtd *xmlDtdPtr;
  180.  
  181. /*
  182.  * A attribute of an XML node.
  183.  */
  184. typedef struct xmlAttr {
  185. #ifndef XML_WITHOUT_CORBA
  186.     void           *_private;    /* for Corba, must be first ! */
  187.     void           *vepv;    /* for Corba, must be next ! */
  188. #endif
  189.     xmlElementType  type;       /* XML_ATTRIBUTE_NODE, must be third ! */
  190.     struct xmlNode *node;    /* attr->node link */
  191.     struct xmlAttr *next;    /* parent->childs link */
  192.     const CHAR     *name;       /* the name of the property */
  193.     struct xmlNode *val;        /* the value of the property */
  194. } xmlAttr;
  195. typedef xmlAttr *xmlAttrPtr;
  196.  
  197. /*
  198.  * A node in an XML tree.
  199.  */
  200. typedef struct xmlNode {
  201. #ifndef XML_WITHOUT_CORBA
  202.     void           *_private;    /* for Corba, must be first ! */
  203.     void           *vepv;    /* for Corba, must be next ! */
  204. #endif
  205.     xmlElementType  type;    /* type number in the DTD, must be third ! */
  206.     struct xmlDoc  *doc;    /* the containing document */
  207.     struct xmlNode *parent;    /* child->parent link */
  208.     struct xmlNode *next;    /* next sibling link  */
  209.     struct xmlNode *prev;    /* previous sibling link  */
  210.     struct xmlNode *childs;    /* parent->childs link */
  211.     struct xmlNode *last;    /* last child link */
  212.     struct xmlAttr *properties;    /* properties list */
  213.     const CHAR     *name;       /* the name of the node, or the entity */
  214.     xmlNs          *ns;         /* pointer to the associated namespace */
  215.     xmlNs          *nsDef;      /* namespace definitions on this node */
  216.     CHAR           *content;    /* the content */
  217. } _xmlNode;
  218. typedef _xmlNode xmlNode;
  219. typedef _xmlNode *xmlNodePtr;
  220.  
  221. /*
  222.  * An XML document.
  223.  */
  224. typedef struct xmlDoc {
  225. #ifndef XML_WITHOUT_CORBA
  226.     void           *_private;    /* for Corba, must be first ! */
  227.     void           *vepv;    /* for Corba, must be next ! */
  228. #endif
  229.     xmlElementType  type;       /* XML_DOCUMENT_NODE, must be second ! */
  230.     char           *name;    /* name/filename/URI of the document */
  231.     const CHAR     *version;    /* the XML version string */
  232.     const CHAR     *encoding;   /* encoding, if any */
  233.     int             compression;/* level of zlib compression */
  234.     int             standalone; /* standalone document (no external refs) */
  235.     struct xmlDtd  *intSubset;    /* the document internal subset */
  236.     struct xmlDtd  *extSubset;    /* the document external subset */
  237.     struct xmlNs   *oldNs;    /* Global namespace, the old way */
  238.     struct xmlNode *root;    /* the document tree */
  239. } _xmlDoc;
  240. typedef _xmlDoc xmlDoc;
  241. typedef xmlDoc *xmlDocPtr;
  242.  
  243. /*
  244.  * A buffer structure
  245.  */
  246.  
  247. typedef struct xmlBuffer {
  248.     CHAR *content;        /* The buffer content UTF8 */
  249.     unsigned int use;        /* The buffer size used */
  250.     unsigned int size;        /* The buffer size */
  251. } _xmlBuffer;
  252. typedef _xmlBuffer xmlBuffer;
  253. typedef xmlBuffer *xmlBufferPtr;
  254.  
  255. /*
  256.  * Variables.
  257.  */
  258. extern xmlNsPtr baseDTD;
  259. extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
  260. extern int xmlIndentTreeOutput;  /* try to indent the tree dumps */
  261.  
  262. /*
  263.  * Handling Buffers.
  264.  */
  265.  
  266. xmlBufferPtr xmlBufferCreate(void);
  267. void xmlBufferFree(xmlBufferPtr buf);
  268. int xmlBufferDump(FILE *file, xmlBufferPtr buf);
  269. void xmlBufferAdd(xmlBufferPtr buf, const CHAR *str, int len);
  270. void xmlBufferCat(xmlBufferPtr buf, const CHAR *str);
  271. void xmlBufferCCat(xmlBufferPtr buf, const char *str);
  272.  
  273. /*
  274.  * Creating/freeing new structures
  275.  */
  276. xmlDtdPtr xmlCreateIntSubset(xmlDocPtr doc, const CHAR *name,
  277.                     const CHAR *ExternalID, const CHAR *SystemID);
  278. xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
  279.                     const CHAR *ExternalID, const CHAR *SystemID);
  280. void xmlFreeDtd(xmlDtdPtr cur);
  281. xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *prefix);
  282. xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *prefix);
  283. void xmlFreeNs(xmlNsPtr cur);
  284. xmlDocPtr xmlNewDoc(const CHAR *version);
  285. void xmlFreeDoc(xmlDocPtr cur);
  286. xmlAttrPtr xmlNewDocProp(xmlDocPtr doc, const CHAR *name,
  287.                                 const CHAR *value);
  288. xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
  289.                              const CHAR *value);
  290. void xmlFreePropList(xmlAttrPtr cur);
  291. void xmlFreeProp(xmlAttrPtr cur);
  292. xmlAttrPtr xmlCopyProp(xmlAttrPtr cur);
  293. xmlAttrPtr xmlCopyPropList(xmlAttrPtr cur);
  294. xmlDtdPtr xmlCopyDtd(xmlDtdPtr dtd);
  295. xmlDocPtr xmlCopyDoc(xmlDocPtr doc, int recursive);
  296.  
  297. /*
  298.  * Creating new nodes
  299.  */
  300. xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
  301.                              const CHAR *name, CHAR *content);
  302. xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name);
  303. xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
  304.                               const CHAR *name, CHAR *content);
  305. xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
  306. xmlNodePtr xmlNewText(const CHAR *content);
  307. xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
  308. xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
  309. xmlNodePtr xmlNewDocComment(xmlDocPtr doc, const CHAR *content);
  310. xmlNodePtr xmlNewComment(const CHAR *content);
  311. xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name);
  312. xmlNodePtr xmlCopyNode(xmlNodePtr node, int recursive);
  313. xmlNodePtr xmlCopyNodeList(xmlNodePtr node);
  314.  
  315. /*
  316.  * Navigating
  317.  */
  318. xmlNodePtr xmlGetLastChild(xmlNodePtr parent);
  319. int xmlNodeIsText(xmlNodePtr node);
  320.  
  321. /*
  322.  * Changing the structure
  323.  */
  324. xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
  325. void xmlUnlinkNode(xmlNodePtr cur);
  326.  
  327. xmlNodePtr xmlTextMerge(xmlNodePtr first, xmlNodePtr second);
  328. void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
  329.  
  330. void xmlFreeNodeList(xmlNodePtr cur);
  331. void xmlFreeNode(xmlNodePtr cur);
  332.  
  333. /*
  334.  * Namespaces
  335.  */
  336. xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
  337.                             const CHAR *nameSpace);
  338. xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
  339.                                   const CHAR *href);
  340. void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
  341. xmlNsPtr xmlCopyNamespace(xmlNsPtr cur);
  342. xmlNsPtr xmlCopyNamespaceList(xmlNsPtr cur);
  343.  
  344. /*
  345.  * Changing the content.
  346.  */
  347. xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
  348.                              const CHAR *value);
  349. CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
  350. xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value);
  351. xmlNodePtr xmlStringLenGetNodeList(xmlDocPtr doc, const CHAR *value,
  352.                                           int len);
  353. CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine);
  354. void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
  355. void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
  356. void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
  357. void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
  358. CHAR *xmlNodeGetContent(xmlNodePtr cur);
  359.  
  360. /*
  361.  * Internal, don't use
  362.  */
  363. void xmlBufferWriteCHAR(xmlBufferPtr buf, const CHAR *string);
  364. void xmlBufferWriteChar(xmlBufferPtr buf, const char *string);
  365. void xmlBufferWriteQuotedString(xmlBufferPtr buf, const CHAR *string);
  366.  
  367. /*
  368.  * Saving
  369.  */
  370. void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
  371. void xmlDocDump(FILE *f, xmlDocPtr cur);
  372. int xmlSaveFile(const char *filename, xmlDocPtr cur);
  373.  
  374. /*
  375.  * Compression
  376.  */
  377. int  xmlGetDocCompressMode (xmlDocPtr doc);
  378. void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
  379. int  xmlGetCompressMode(void);
  380. void xmlSetCompressMode(int mode);
  381.  
  382. #ifdef __cplusplus
  383. }
  384. #endif
  385.  
  386. #endif /* __XML_TREE_H__ */
  387.  
  388.